package jmine.tec.utils.collection;

import java.util.Enumeration;
import java.util.Iterator;

/**
 * Adapta um iterator para um enumeration
 * 
 * @author takeshi
 * @param <E>
 */
public final class IteratorEnumeration<E> implements Enumeration<E> {
    private final Iterator<E> iterator;

    /**
     * @param iterator {@link Iterator}
     */
    public IteratorEnumeration(final Iterator<E> iterator) {
        super();
        this.iterator = iterator;
    }

    /**
     * @param iterable {@link Iterable}
     */
    public IteratorEnumeration(final Iterable<E> iterable) {
        this(iterable.iterator());
    }

    /**
     * @return boolean
     */
    public boolean hasMoreElements() {
        return this.iterator.hasNext();
    }

    /**
     * @return E
     */
    public E nextElement() {
        return this.iterator.next();
    }

}
